﻿Public Class Scrum
    Public pj As Pj = New Pj
    Public cafes As New List(Of Cafe)
    Public comerciales As New List(Of Comercial)
    Private muros As New List(Of PictureBox)
    Private perderEnergia As Byte
    Dim metros As Integer
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'CALCULAR MOVIMIENTOS
        If pj.mover() = -1 Then
            Exit Sub
        End If
        metros += pj.vx
        Label3.Text = metros
        For i = comerciales.Count - 1 To 0 Step -1
            comerciales(i).mover()
            comerciales(i).animar()
        Next
        For i = cafes.Count - 1 To 0 Step -1
            cafes(i).mover()
        Next
        pj.animar()
        perderEnergia += 1 + pj.vx / 3
        If perderEnergia > 3 Then
            If ProgressBar1.Value = 0 Then
                My.Computer.Audio.Play(My.Resources.laughter_2,
AudioPlayMode.Background)
                perder()
                Exit Sub
            End If
            ProgressBar1.Value -= 1
            perderEnergia = 0
        End If
        If metros >= 20000 And pj.Top = pj.pos * 50 Then
     
            pj.vy = 10
            pj.vx = 10
        ElseIf metros >= 6000 And pj.Top = pj.pos * 50 Then
         
            pj.vy = 5
            pj.vx = 7
        ElseIf metros >= 1500 And pj.Top = pj.pos * 50 Then
          
            pj.vy = 2
            pj.vx = 3
        End If
        'MOVER MUROS
        For Each muro In muros
            muro.Left -= pj.vx
            If muro.Left < -389 Then
                muro.Left = 389
            End If
        Next
    End Sub

    Private Sub Scrum_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            Timer1.Stop()
            Main.cambio(0)
        End If

        If pj.Top = pj.pos * 50 Then 'Para solo mover cuando ya esta parado
            If (e.KeyCode = Keys.W Or e.KeyCode = Keys.NumPad4) And pj.pos > 1 Then
                pj.pos -= 1
            ElseIf (e.KeyCode = Keys.S Or e.KeyCode = Keys.NumPad1) And pj.pos < 5 Then
                pj.pos += 1
            End If
        End If

    End Sub

    Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(pj)
        muros.Add(muro1)
        muros.Add(muro2)
        muros.Add(muro3)
        muros.Add(muro4)
    End Sub
    Public Sub generar()
        For index = 1 To 6
            Me.comerciales.Add(New Comercial)
            Me.Controls.Add(comerciales(comerciales.Count - 1))
        Next
        Me.cafes.Add(New Cafe)
        Me.Controls.Add(cafes(cafes.Count - 1))
    End Sub
    Private Sub Game_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Timer1.Start()
    End Sub
    Public Function choque(ByVal TipoChoque As Integer) As Boolean
        If TipoChoque = 1 Then
            If ProgressBar1.Value < 101 Then
                My.Computer.Audio.Play(My.Resources.laughter_2,
           AudioPlayMode.Background)
                perder()
                Return False
            End If
            My.Computer.Audio.Play(My.Resources.scream_male,
             AudioPlayMode.Background)
            ProgressBar1.Value -= 100
        ElseIf TipoChoque = 2 Then
            If ProgressBar1.Value >= 930 Then
                ProgressBar1.Value = 1000
            Else
                ProgressBar1.Value += 70
                My.Computer.Audio.Play(My.Resources.slurp,
 AudioPlayMode.Background)
            End If
        End If
        Return True
    End Function
    Private Sub perder()
        Timer1.Stop()
        DialogResult = MessageBox.Show("Has perdido :'( tu puntuación ha sido " & metros & vbNewLine & "Aceptar para volver a jugar" & vbNewLine & "Cancelar para ver puntuaciones", "PELAU", MessageBoxButtons.OKCancel)
        Main.score.cargar(0)
        Main.score.comprobar(metros, 0)
        If DialogResult = Windows.Forms.DialogResult.OK Then
            Main.reiniciar(0)
        Else
            Main.cambio(1)
        End If
    End Sub
End Class